package com.ddxz.flink

import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.apache.flink.streaming.api.scala._
import org.apache.flink.streaming.api.windowing.time.Time

object Sock {
  def main(args: Array[String]): Unit = {
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    val soc = env.socketTextStream("192.168.72.100", 9876)
    val rst = soc.flatMap {_.toLowerCase.split("\\W+") filter{_.nonEmpty } }
      .map{(_, 1)}
      .keyBy(_._1)
      .timeWindow(Time.seconds(5))
      .sum(1)
    rst.print()
    env.execute("Socket")
  }
}
